home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_MacPaint / Source / shared.subproj / RCS / ErrorInfo.m,v < prev    next >
Text File  |  1995-06-12  |  6KB  |  212 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @@;
  7.  
  8.  
  9. 1.4
  10. date     92.04.27.20.35.37;  author death;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     92.03.29.12.10.26;  author death;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     92.02.09.18.40.15;  author death;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     92.02.09.14.02.23;  author death;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @The implementation file for the ErrorInfo object.  See ErrorInfo.rtf for documentation.
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @Miscellaneous changes.
  38. @
  39. text
  40. @/*
  41. ====================================================================
  42. This is the implementation file for the ErrorInfo class.  Full documentation for this class can be found in the ErrorInfo.rtf file.  I will not duplicate all that fine information here.
  43.     This is $Revision: 1.3 $ of this file
  44.     It was last modified by $Author: death $ on $Date: 92/03/29 12:10:26 $
  45. Note that this file was created while using the New Century Schoolbook Roman typeface.  You may find that some things line up strangely if you don't use that family.
  46. $Log:    ErrorInfo.m,v $
  47. Revision 1.3  92/03/29  12:10:26  death
  48.  turns out that 2.0 wants init calls to be in the object, not the class.
  49. modifed accordingly, and moved free into object.
  50.  
  51. Revision 1.2  92/02/09  18:40:15  death
  52. miscelaneous modifications, including fixing the bug noted in the doc that states that there was not enough dealing with error conditions.  when malloc returns a null pointer, we check lest we copy onto it.  Explicit casts are made to note when we are ignoring return values (e.g. from strcpy).
  53.  
  54. Revision 1.1  92/02/09  14:02:23  death
  55. Initial revision
  56.  
  57. ====================================================================
  58. */
  59.  
  60. //
  61. //    Import our own definition
  62. //
  63. #import "ErrorInfo.h"
  64. #import <strings.h>
  65. #import <stdlib.h>
  66.  
  67.  
  68. @@implementation ErrorInfo
  69.  
  70. /**********************************************************************************
  71.     This is the main initalization method.  It really doens't do much.  Initalize the superclass, and fill in the instance variables based on what we were passed.  If there is a text string, allocate space for it and store it.
  72.     There is no 'alloc' for this class.  We just use the superclass'.
  73. **********************************************************************************/
  74. - (id) initErrorWithCode: (long int) code Text: (Cstring) text Kind: (long int) kind
  75. {
  76.     [super init];
  77.     errorKind = kind;
  78.     errorCode = code;
  79.     if (text != NULL)
  80.     {
  81.     errorText = (Cstring) malloc (strlen(text) + 1);
  82.     if (errorText != NULL)
  83.         (void) strcpy(errorText, text);    // we don't care about getting a pointer back
  84.     }
  85.     return self;
  86. }
  87.  
  88.  
  89. /**********************************************************************************
  90.     This just calls initErrorWithCode:Text:Kind: with its given parameters.
  91. **********************************************************************************/
  92. - (id) initErrorWithCode: (long int) code Text: (Cstring) text
  93. {
  94.     return [self initErrorWithCode: code Text: text Kind: ERRKIND_GENERAL];
  95. }
  96.  
  97.  
  98. /*********************************************************************************
  99.     In this method, we merely free the object.  This action involves getting rid of the text string if it is there, and then asking our superclass to free. 
  100. **********************************************************************************/
  101. - free
  102. {
  103.     if (errorText != NULL)
  104.         free(errorText);
  105.     return [super    free];
  106. }
  107.  
  108.  
  109. /*********************************************************************************
  110.     this method merely serves to return the kind of the error to the caller.
  111. **********************************************************************************/
  112. - (long int) getErrorKind
  113. {
  114.     return errorKind;
  115. }
  116.  
  117.  
  118. /*********************************************************************************
  119. Make a copy of the string and return it to the caller.  If this string is null, this all works transparently anyay.
  120. **********************************************************************************/
  121. - (Cstring) getErrorText
  122. {
  123.     Cstring    tempString;
  124.     
  125.     
  126.     //    Allocate as much space as the length of the string +1
  127.     //
  128.     tempString = (Cstring) malloc (strlen(errorText) + 1);
  129.     
  130.     //    Make a copy of the error text into the new location
  131.     //
  132.     if (tempString != NULL)
  133.         (void) strcpy(tempString, errorText);    // we don't care about getting a pointer back
  134.     
  135.     //    Finally, return a pointer to this new string.
  136.     //
  137.     return tempString;
  138. }
  139.  
  140.  
  141. /*********************************************************************************
  142.     this method merely serves to return the error's code to the caller.
  143. **********************************************************************************/
  144. - (long int) getErrorCode
  145. {
  146.     return errorCode;
  147. }
  148.  
  149. @@end
  150. @
  151.  
  152.  
  153. 1.3
  154. log
  155. @ turns out that 2.0 wants init calls to be in the object, not the class.
  156. modifed accordingly, and moved free into object.
  157. @
  158. text
  159. @d4 2
  160. a5 2
  161.     This is $Revision: 1.2 $ of this file
  162.     It was last modified by $Author: death $ on $Date: 92/02/09 18:40:15 $
  163. d8 4
  164. d37 1
  165. a37 1
  166.     [super initialize];
  167. @
  168.  
  169.  
  170. 1.2
  171. log
  172. @miscelaneous modifications, including fixing the bug noted in the doc that states that there was not enough dealing with error conditions.  when malloc returns a null pointer, we check lest we copy onto it.  Explicit casts are made to note when we are ignoring return values (e.g. from strcpy).
  173. @
  174. text
  175. @d4 2
  176. a5 2
  177.     This is $Revision: 1.1 $ of this file
  178.     It was last modified by $Author: death $ on $Date: 92/02/09 14:02:23 $
  179. d8 3
  180. d31 1
  181. a31 1
  182. + (id) initErrorWithCode: (long int) code Text: (Cstring) text Kind: (long int) kind
  183. d49 1
  184. a49 1
  185. + (id) initErrorWithCode: (long int) code Text: (Cstring) text
  186. d58 1
  187. a58 1
  188. + free
  189. @
  190.  
  191.  
  192. 1.1
  193. log
  194. @Initial revision
  195. @
  196. text
  197. @d4 2
  198. a5 2
  199.     This is $Revision$ of this file
  200.     It was last modified by $Author$ on $Date$
  201. d7 4
  202. a10 1
  203. $Log$
  204. d35 3
  205. a37 2
  206.         errorText = (Cstring) malloc (strlen(text) + 1);
  207.         strcpy(errorText, text);
  208. d86 2
  209. a87 1
  210.     strcpy(tempString, errorText);
  211. @
  212.